//
//  UIButton+Extion.swift
//  小陈微博Swift用纯代码创建
//
//  Created by 小陈 on 16/3/3.
//  Copyright © 2016年 小陈. All rights reserved.
//

import UIKit

extension UIButton{
    
    convenience init(ImageName:String,title:String,font:CGFloat){
            self.init()
    
        // 设置背景图片
        setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)

            self.setImage(UIImage(named: ImageName), forState: UIControlState.Normal)
        
            self.setTitle(title, forState: UIControlState.Normal)
            self.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
            self.titleLabel?.font = UIFont.systemFontOfSize(font)
        

    }

//    // 参数可以设置默认值
    convenience init(imageName: String, bkgImageName: String = "timeline_card_bottom_background", title: String, font: CGFloat = 11) {
        // 调用当前类的指定构造函数
        self.init()
        
        // 设置背景图片
        setBackgroundImage(UIImage(named: bkgImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: "\(bkgImageName)_highlighted"), forState: UIControlState.Highlighted)
        
        // 设置图片
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        // 设置标题内容和大小颜色
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(11)
    }

}